#!/bin/sh

# 获取jar包所在的目录
JAR_DIR="/opt/light1.0"

# 设置JAR文件的相对路径
JAR_PATH="$JAR_DIR/light-1.0.0.jar"

# 启动函数
start() {
    # 进入脚本所在目录
    cd "$JAR_DIR"
    nohup java -jar "$JAR_PATH" &
}

# 停止函数
stop() {
    PID=$(ps -ef | grep "$JAR_PATH" | grep -v grep | awk '{ print $2 }')
    if [ -z "$PID" ]; then
        echo "Application is already stopped"
    else
        echo "kill $PID"
        kill $PID
    fi
}

# 查看日志函数
log() {
    tail -f "$JAR_DIR/nohup.out"
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    log)
        log
        ;;
    *)
        echo "Usage: $0 {start|stop|log}"
        exit 1
        ;;
esac